package sw6.visualschedule.entities;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;

@DatabaseTable(tableName = "repeatpatterns")
public class RepeatPattern {

    public static final String ACTIVITY_ID_FIELD = "activity_id";
    public static final String DAY_IN_WEEK_FIELD = "day";
    public static final int DEFAULT_HOUR_OF_DAY = 12;
    public static final int DEFAULT_MINUTE_OF_DAY = 0;
    
    public static final String HOUR_OF_THE_DAY_FIELD = "hour";
    public static final String MINUTE_OF_THE_HOUR_FIELD = "minute";

    @DatabaseField(columnName = ACTIVITY_ID_FIELD, foreign = true)
    private transient ScheduleActivity mActivity;
    
    @DatabaseField(columnName = DAY_IN_WEEK_FIELD)
    private transient Day mDayInWeek;

    @DatabaseField(columnName = HOUR_OF_THE_DAY_FIELD)
    private transient int mHourOfTheDay;
    
    @DatabaseField(generatedId = true)
    private transient Integer mId;
    
    @DatabaseField(columnName = MINUTE_OF_THE_HOUR_FIELD)
    private transient int mMinuteOfTheHour;
    
    public RepeatPattern(final ScheduleActivity activity) {
        mActivity = activity;
        mHourOfTheDay = DEFAULT_HOUR_OF_DAY;
        mMinuteOfTheHour = DEFAULT_MINUTE_OF_DAY;
        
    }
    
    RepeatPattern() {
        // all persisted classes must define a no-arg constructor with at least package visibility
    }
    
    public ScheduleActivity getActivity() {
        return mActivity;
    }
    
    public Day getDayInWeek() {
        return mDayInWeek;
    }
    
    public int getHourOfTheDay() {
        return mHourOfTheDay;
    }
    
    public Integer getId() {
        return mId;
    }
    
    public int getMinuteOfTheHour() {
        return mMinuteOfTheHour;
    }
    
    public void setDayInWeek(final Day day) {
        mDayInWeek = day;
    }
    
    public void setHourOfTheDay(final int hourOfTheDay) {
        mHourOfTheDay = hourOfTheDay;
    }
    
    public void setMinuteOfTheHour(final int minuteOfTheHour) {
        mMinuteOfTheHour = minuteOfTheHour;
    }
    
    @Override
    public String toString() {
        return String.format("On %1$s at %2$02d:%3$02d", mDayInWeek.toString(), mHourOfTheDay, mMinuteOfTheHour);
    }
    
}
